#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
账本 - 账单申请URL功能使用示例
"""

import os
import sys

# 添加项目根目录到Python路径，确保能够导入jlpay包
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))

from examples.base_example import BaseExample
from jlpay.services.ledger.bill_service import BillService
from jlpay.model.ledger.bill import BillApplyUrlRequest


class BillApplyUrlExample(BaseExample):
    """账单申请URL示例类"""
    
    def __init__(self):
        """初始化示例类"""
        super().__init__("examples.ledger.bill")
        self.service = BillService(self.config)
    
    def build_bill_apply_url_request(self):
        """构建账单申请URL请求"""
        request = BillApplyUrlRequest()
        
        # 设置请求参数
        request.set_org_code("50720711")
        request.set_bill_date("2024-08-15")
        
        return request
    
    def demo(self):
        """执行账单申请URL示例"""
        self.logger.info("开始执行账单申请URL示例")
        
        # 创建账单申请URL请求
        request = self.build_bill_apply_url_request()
        
        # 发送请求
        response = self.send_request_and_handle_response(
            self.service.apply_bill_url,
            "账单申请URL",
            request
        )
        
        # 处理响应结果
        if response and response.is_success():
            self.logger.info(f"响应报文：{response.to_dict()}")


if __name__ == "__main__":
    logger = BillApplyUrlExample().logger
    logger.info("=" * 50)
    logger.info("===== 账单申请URL示例 开始 =====")
    logger.info("=" * 50)
    
    example = BillApplyUrlExample()
    example.demo()
    
    logger.info("=" * 50)
    logger.info("===== 账单申请URL示例执行完毕 =====")
    logger.info("=" * 50) 